package com.xc.xcmanage.web.controller;

import com.xc.xcmanage.domain.AjaxResult;
import com.xc.xcmanage.domain.dto.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户的相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @ApiOperation("用户列表")
    @PreAuthorize("hasAuthority('system:user:list')")
    @GetMapping("/list")
    public AjaxResult list(){

        int num = 1/0;
        return AjaxResult.success();
    }

    @GetMapping("/info")
    public AjaxResult info(){
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        return AjaxResult.success()
                .put("user",loginUser.getSysUser())
                .put("roles","admin")
                .put("permissions",loginUser.getPerms());
    }
}
